package com.ncloud.resman.service.impl;

import com.ncloud.resman.entity.DeviceServer;
import com.ncloud.resman.entity.ExportServer;
import com.ncloud.resman.mapper.DeviceServerMapper;
import com.ncloud.resman.service.DeviceServerService;
import com.ncloud.resman.service.SequenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by shiqiang on 2017/8/15.
 */
@Service
public class DeviceServerServiceImpl implements DeviceServerService{
    @Autowired
    private DeviceServerMapper deviceServerMapper;
    @Autowired
    private SequenceService sequenceService;
    @Override
    public DeviceServer getDeviceServerByDeviceId(Long deviceId) {
        return deviceServerMapper.getDeviceServerByDeviceId(deviceId);
    }

    @Override
    public int insertDeviceServer(DeviceServer deviceServer) {
        if(deviceServer.getDeviceId() == null){
            Long id = sequenceService.getSequence("device_id_seq");
            deviceServer.setDeviceId(id);
        }
        deviceServer.setCreateDate(new Date());
        return deviceServerMapper.insertDeviceServer(deviceServer);
    }

    @Override
    public int updateDeviceServer(DeviceServer deviceServer) {
        deviceServer.setUpdateDate(new Date());
        return deviceServerMapper.updateDeviceServer(deviceServer);
    }

    @Override
    public int deleteDeviceServer(Long deviceId) {
        return deviceServerMapper.deleteDeviceServer(deviceId);
    }

	@Override
	public List<ExportServer> getServerInfoBySnNum(String snNum) {	
		return deviceServerMapper.getServerInfoBySnNum(snNum);
	}
}
